const express = require('express')
const app = express()
//引入querystring方法解析字符串
const qs = require('querystring')
//设置自定义中间体
app.use((req,res,next)=>{
   //业务代码
   let str = ''
   req.on('data',(chunk)=>{
    str += chunk
   })
  req.on('end',()=>{
    const body = qs.parse(str)
//用req.body挂载解析出来的数据并传递到下游
    req.body = body
  next()
})
  })

app.post('/user',(req,res)=>{
    console.log(req.body)
    
    res.send(req.body)
})

app.listen(80,() => {
 console.log('http://127.0.0.1')
})